<template>
    <div style="background:#fff;height:100%">
      <div class="enterpriseInfoTab">
          <ul>
              <li>
                  <a  @click="enterpriseInfoRouter('/dlyrl/hr/enterpriserole/EnterpriseRoleInformationList')">
              企业岗位管理
              </a>
              </li>
              <li class="defaultActive">
                  <a @click="enterpriseInfoRouter('/dlyrl/hr/enterprmenu/EnterpriseMenuList')">
              企业菜单管理
              </a>
              </li>
              <li>
                  <a @click="enterpriseInfoRouter('/dlyrl/hr/roleenterpriseanduser/RoleEnterpriseanduserList')">
              岗位用户管理
              </a>
              </li>
              <li>
                  <a @click="enterpriseInfoRouter('/dlyrl/hr/menuenterpriserole/MenuEnterpriseRoleList')">
              岗位菜单管理
              </a>
              </li>
          </ul>
      </div>
      <div  style="padding:10px 15px">
        <el-row>
          <el-button v-if="hasPermission('dlyrl:hr:enterprmenu:enterpriseMenu:add')" type="primary" size="small" icon="el-icon-plus" @click="add()">新建</el-button>
        </el-row>
        <el-table
          :cell-style="cellStyle" style="border:1px solid #d6cfe2;"
          :header-cell-class-name="cellHeadStyle" 
          :row-class-name="tableRowClassName"
          :data="dataList"
          isBigData
          isTreeTable
          size="small"
          v-loading = "loading"
          row-key="id"
          class="table treetable">
        <el-table-column
            prop="name"
            show-overflow-tooltip
            label="菜单名">
          </el-table-column>
        <el-table-column
            prop="ename"
            show-overflow-tooltip
            label="英文名">
          </el-table-column>
        <el-table-column
            prop="addressUrl"
            show-overflow-tooltip
            label="地址url">
          </el-table-column>
        <el-table-column
            prop="sort"
            show-overflow-tooltip
            label="排序">
          </el-table-column>
        <el-table-column
            prop="remarks"
            show-overflow-tooltip
            label="备注信息">
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            fixed="right"
            :key="Math.random()"
            width="340"
            label="操作">
            <template  slot-scope="scope">
              <el-button v-if="hasPermission('dlyrl:hr:enterprmenu:enterpriseMenu:view')" type="text" size="mini" icon="el-icon-view" @click="view(scope.row.id)">查看</el-button>
              <el-button v-if="hasPermission('dlyrl:hr:enterprmenu:enterpriseMenu:edit')" type="text" size="mini" icon="el-icon-edit" @click="edit(scope.row.id)">修改</el-button>
              <el-button v-if="hasPermission('dlyrl:hr:enterprmenu:enterpriseMenu:del')" type="text" size="mini" icon="el-icon-delete" @click="del(scope.row.id)">删除</el-button>
              <el-button v-if="hasPermission('dlyrl:hr:enterprmenu:enterpriseMenu:add')" type="text" size="mini" icon="el-icon-circle-plus-outline" @click="addChild(scope.row.id, scope.row.name)">添加下级企业菜单</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
        <!-- 弹窗, 新增 / 修改 -->
      <EnterpriseMenuForm  ref="enterpriseMenuForm" @refreshDataList="refreshList"></EnterpriseMenuForm>
  </div>
</template>

<script>
  import tableStyles from '../../../../../utils/mixins.js'
  import EnterpriseMenuForm from './EnterpriseMenuForm'
  export default {
    mixins: [tableStyles],
    data () {
      return {
        dataList: [],
        loading: false
      }
    },
    components: {
      EnterpriseMenuForm
    },
    activated () {
      this.refreshList()
    },

    methods: {
       //跳转
      enterpriseInfoRouter(url){
         this.$router.push(url)
      },
      // 获取数据列表
      refreshList () {
        this.loading = true
        this.$http({
          url: '/dlyrl/hr/enterprmenu/enterpriseMenu/treeData',
          method: 'get'
        }).then(({data}) => {
          this.dataList = data.treeData
          this.loading = false
        })
      },
        // 新增下级
      addChild (id, name) {
        this.$refs.enterpriseMenuForm.init('addChild', {id: '', parent: {id: id, name: name}})
      },
       // 新增
      add () {
        this.$refs.enterpriseMenuForm.init('add', {id: '', parent: {id: '', name: ''}})
      },
      // 修改
      edit (id) {
        this.$refs.enterpriseMenuForm.init('edit', {id: id, parent: {id: '', name: ''}})
      },
      // 查看
      view (id) {
        this.$refs.enterpriseMenuForm.init('view', {id: id, parent: {id: '', name: ''}})
      },
      // 删除
      del (id) {
        this.$confirm(`确定删除所选项吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          this.$http({
            url: '/dlyrl/hr/enterprmenu/enterpriseMenu/delete',
            method: 'delete',
            params: {'id': id}
          }).then(({data}) => {
            if (data && data.success) {
              this.$message.success(data.msg)
              this.refreshList()
            }
            this.loading = false
          })
        })
      }
    }
  }
</script>
<style scoped>
ul {
  margin: 0;
}
</style>